<?
$query = "select * from tbl_companies";
$result = mysql_query($query);

$ctype_query = "select * from tbl_company_type";
$ctype_result = mysql_query($ctype_query);

$rpt_query = "select * from tbl_reporting_type";
$rpt_result = mysql_query($rpt_query);

$asrRates_query = "select * from tbl_asr_rates";
$asrRates_result = mysql_query($asrRates_query);

$agcy_query = "select * from tbl_agency_agreement";
$agy_result = mysql_query($agcy_query);

$whsquery = "select * from tbl_whis_carriers";
$whsresult = mysql_query($whsquery);

if($_POST['csubmit'] == 'Create'){
	extract($_POST);
	$insert_query = "INSERT INTO tbl_companies (c_name,c_nickname,c_billing_address1,c_billing_address2,c_billing_city," .
			"c_billing_state,c_billing_zipcode,c_billing_country,c_phone_number,c_phone_extension,c_fax_number,reporting_type,ct_id) " .
			"values ('$c_name','$c_nickname','$c_billing_address1','$c_billing_address2','$c_billing_city','$c_billing_state','$c_billing_zipcode','$c_billing_country','$c_phone_number','$c_phone_extension','$c_fax_number','$reporting_type','$c_type')";
	if(mysql_query($insert_query)){?>
	<script>
	$(document).ready(function(){
		$("#success").text("The new Company Profile has been created.").show();
	});
	</script>
	<?
	}
}
$query = "select * from tbl_companies";
$result = mysql_query($query);
?>
<style type="text/css">
.hide{
	display:none;
}
.show{
	display:block;
}
</style>
<script type="text/javascript" >
function opendialog(obj,type)
{
	openalertdialog(obj,type);
}
function openalertdialog(id,type)
{
	jQuery("#dialog").dialog("destroy");
	jQuery("#dialog").dialog({
		resizable: false,
		height:148,
		modal: true,
		buttons: {
				'Delete': function() {
				if(type == 'company')
				{
					jQuery.post("/aec1/pages/delete_company.php",{id:id},function(data){
					jQuery('#cmpy_del'+id).hide(function(){
						jQuery('#cmpy_del'+id).remove();
					});
					$( "#dialog:ui-dialog" ).dialog( "destroy" );
					$( "#dialog-message" ).dialog({
					modal: true,
					buttons: {
						Ok: function() {
							$(this).dialog( "close" );
						}
					}
					});
					});
				}
				else if(type=='asr')
				{
					jQuery.post("/aec1/pages/delete_asrRates.php",{id:id},function(data){
					jQuery('#asr_del'+id).hide(function(){
						jQuery('#asr_del'+id).remove();
					});
					$( "#dialog:ui-dialog" ).dialog( "destroy" );
					$( "#dialog-message" ).dialog({
					modal: true,
					buttons: {
						Ok: function() {
							$(this).dialog( "close" );
						}
					}
					});
					});
				}
				else if(type == 'agency'){
					jQuery.post("/aec1/pages/delete_agency_agreement.php",{id:id},function(data){
					jQuery('#agcy_del'+id).hide(function(){
						jQuery('#agcy_del'+id).remove();
					});
					$( "#dialog:ui-dialog" ).dialog( "destroy" );
					$( "#dialog-message" ).dialog({
					modal: true,
					buttons: {
						Ok: function() {
							$(this).dialog( "close" );
						}
					}
					});
					});
				}
				else if(type == 'delete wholeSale')
				{
					jQuery.post("/aec1/pages/update_cprofile.php",{name:type,id:id},function(data){
					jQuery('#whis_del'+id).hide(function(){
						jQuery('#whis_del'+id).remove();
					});
					$( "#dialog:ui-dialog" ).dialog( "destroy" );
					$( "#dialog-message" ).dialog({
					modal: true,
					buttons: {
						Ok: function() {
							$(this).dialog( "close" );
						}
					}
					});
					});
				}
				jQuery(this).dialog('close');
				},
				Cancel: function() {
				jQuery(this).dialog('close');
				}
			}
		});
}
</script>
<script>
  $(document).ready(function(){
    $("#add_cmpyfrm").validate();
  });
  function editcmpy(id,name){
  	$(".viewList"+name).removeClass( 'show').addClass('hide');
  	if(name == 'company'){
  	$.post("/aec1/pages/edit_cmpy_profile.php",{cid:id},function(data){
  		if(data!=''){
  			$('.editCmpy').append(data);
  			}
  	});
  	}else if(name == 'agency'){
  		$.post("/aec1/pages/agency_agreement.php",{aid:id},function(data){
  		if(data!=''){
  			$('.editagy').append(data);}
  		});
  	}else if(name == 'asr'){
  		$.post("/aec1/pages/asr_rates.php",{asrid:id},function(data){
  		if(data!=''){
  			$('.editasr').append(data);}
  		});
  	}else if(name == 'wholeSale'){
  		$.post("/aec1/pages/wholesale_carriers.php",{id:id},function(data){
  		if(data!=''){
  			$('.editwhsc').append(data);}
  		});
  	}
  }
</script>
<?php echo $_POST['msg'];?>
<!-- ui-dialog -->
<div id="dialog-message" title="Success Delete" style="display:none;">
	<p>
		<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
		Selected record has been deleted successfully.
	</p>
</div>
<div id="dialog" title="Dialog Title" style="display:none">
	<p>Are you sure, you want to delete the selected item?</p>
</div>
<span id='error'></span><span id='success'></span>

<p><h1>Company Management</h1></p>
<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Company Profiles</a></li>
		<li><a href="#tabs-2">Agency Agreements</a></li>
		<li><a href="#tabs-3">ASR Rates</a></li>
		<li><a href="#tabs-4">CIC Codes</a></li>
	</ul>
	<div id="tabs-1">
		<div class="viewListcompany show">
		<div><h3>List Of Company Profiles</h3></div><a href='index.php?page=new-company-profile'>Add New</a>
		<table cellspacing='2' cellpadding='5'>
			<tr style="background-color:#0673C5;color:#FFFFFF;">
				<th>Company Id</th>
				<th>Company Name</th>
				<th>Actions</th>
			</tr>
			<? while($cmpy = mysql_fetch_array($result)){?>
			<tr id="cmpy_del<?=$cmpy['c_id'];?>" style="background-color:#E6E9F2;">
				<td><? echo $cmpy['c_id']?></td>
				<td><? echo $cmpy['c_name']?></td>
				<td>
					<span class="ui-icon ui-icon-pencil" title="Edit" onclick="editcmpy(<?=$cmpy['c_id'];?>,'company')" style="float:left;cursor:pointer"></span>
					<!-- <a href="index.php?page=edit-cmpy-profile&Id=<?=$cmpy['c_id'];?>" title="Edit"><div class="ui-icon ui-icon-pencil" style="float:left;"></div></a> -->
					<a href="javascript:void(0)" onclick="opendialog(<?=$cmpy['c_id'];?>,'company')" class="ui-corner-all" title="Delete"><span class="ui-icon ui-icon-trash"></span></a>
				</td>
			</tr>
			<?}?>
		</table>
		</div>
		<div class="editCmpy"></div>
	</div>
	<div id="tabs-2">
		<div class="viewListagency show">
			<div><h3>List Of Agency Agreements</h3></div><a href='index.php?page=agency-agreement'>Add New</a>
			<table cellspacing='2' cellpadding='3'>
				<tr style="background-color:#0673C5;color:#FFFFFF;">
					<th>Id</th>
					<th>LEC Nickname</th>
					<th>CIC Code</th>
					<th>IXC Nickname</th>
					<th>Start Date</th>
					<th>End Date</th>
					<th>Actions</th>
				</tr>
				<? while($agy = mysql_fetch_array($agy_result)){?>
				<tr id="agcy_del<?=$agy['agency_agreement_id'];?>" style="background-color:#E6E9F2;">
					<td><?=$agy['agency_agreement_id'];?></td>
					<td><?=$agy['qry_lec_companies'];?></td>
					<td><?=$agy['whls_carriers'];?></td>
					<td><?=$agy['qry_ixc_companies'];?></td>
					<td><?=$agy['effective_start_date'];?></td>
					<td><?=$agy['effective_end_date'];?></td>
					<td>
						<span class="ui-icon ui-icon-pencil" title="Edit" onclick="editcmpy(<?=$agy['agency_agreement_id'];?>,'agency')" style="float:left;cursor:pointer"></span>
						<!-- <a href="index.php?page=agency-agreement&Id=<?=$agy['agency_agreement_id'];?>" title="Edit"><div class="ui-icon ui-icon-pencil" style="float:left;"></div></a> -->
						<a href="javascript:void(0)" onclick="opendialog(<?=$agy['agency_agreement_id'];?>,'agency')" class="ui-corner-all" title="Delete"><span class="ui-icon ui-icon-trash"></span></a>
					</td>
				</tr>
				<?}?>
			</table>
		</div>
		<div class="editagy"></div>
	</div>
	<div id="tabs-3">
		<div class="viewListasr show">
		<div><h3>List Of ASR Rates</h3></div>
		<a href='index.php?page=asr-rates'>Add New</a>
		<table cellspacing='2' cellpadding='3'>
			<tr style="background-color:#0673C5;color:#FFFFFF;">
				<th>Rt_Id</th>
				<th>C_Nickname</th>
				<th>Rt_Amt</th>
				<th>Start Date</th>
				<th>End Date</th>
				<th>Rt_Type</th>
				<th>Actions</th>
			</tr>
			<? while($asr = mysql_fetch_array($asrRates_result)){?>
			<tr style="background-color:#E6E9F2;" id="asr_del<?=$asr['asr_rate_id'];?>">
				<td><?=$asr['asr_rate_id'];?></td>
				<td><?=$asr['c_nickname'];?></td>
				<td><?=(float)$asr['asr_rate_amount'];?></td>
				<td><?=$asr['asr_rate_eff_start_date'];?></td>
				<td><?=$asr['asr_rate_eff_end_date'];?></td>
				<td><?=$asr['rt_rate_type'];?></td>
				<td>
					<span class="ui-icon ui-icon-pencil" title="Edit" onclick="editcmpy(<?=$asr['asr_rate_id'];?>,'asr')" style="float:left;cursor:pointer"></span>
					<!-- <a href="index.php?page=asr-rates&Id=<?=$asr['asr_rate_id'];?>" title="Edit"><div class="ui-icon ui-icon-pencil" style="float:left;"></div></a> -->
					<a href="javascript:void(0)" onclick="opendialog(<?=$asr['asr_rate_id'];?>,'asr')" class="ui-corner-all" title="Delete"><span class="ui-icon ui-icon-trash"></span></a>
				</td>
			</tr>
			<? }?>
		</table>
		</div>
		<div class="editasr"></div>
	</div>
	<div id="tabs-4">
		<div class="viewListwholeSale show">
		<h3><strong>List Of WholeSale Carriers</strong></h3>
		<a href='index.php?page=wholesale-carriers'>Add New</a>
		<table cellspacing='2' cellpadding='5' style="font-size:1.1em;color:#222222;font-family:Verdana,Arial,sans-serif;">
			<tr style="background-color:#0673C5;color:#FFFFFF;">
				<th>CIC</th>
				<th>Name</th>
				<th>Actions</th>
			</tr>
			<? while($whis = mysql_fetch_array($whsresult)){?>
			<tr id="whis_del<?=$whis['id'];?>" style="background-color:#E6E9F2;">
				<td><?=$whis['whls_carriers_id']?></td>
				<td><?=$whis['whls_carriers_name']?></td>
				<td>
				<span class="ui-icon ui-icon-pencil" title="Edit" onclick="editcmpy(<?=$whis['id'];?>,'wholeSale')" style="float:left;cursor:pointer"></span>
				<!-- <a href="index.php?page=wholesale-carriers&Id=<?=$whis['id'];?>" title="Edit"><div class="ui-icon ui-icon-pencil" style="float:left;"></div></a> -->
				<a href="javascript:void(0)" onclick="opendialog(<?=$whis['id'];?>,'delete wholeSale')" class="ui-corner-all" title="Delete"><span class="ui-icon ui-icon-trash"></span></a>
				</td>
			</tr>
			<?}?>
		</table>
		</div>
		<div class="editwhsc"></div>
	</div>
</div>